<template>
  <div class="liveOpened">
    <div class="liveOpened-switch">
      <div class="liveOpened-switch-header">云直播开关</div>
      <el-form :model="CloudLiveSet" :rules="rules" label-width="207px" class="liveOpened-settingForm">
        <el-form-item label="启用云视频:" prop="switch">
          <span style="color:#409EFF;margin-right:10px;">已启用</span>
          <el-button type="danger" size="mini" @click="handleClickClose">关闭</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>

  import {getTenantId} from '@/utils/auth';
  import {addData, getData} from '@/api/cloud/cloud_live_set';

  export default {

    data() {
      return {
        CloudLiveSet: {
          status: '1'
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getData(getTenantId()).then(response => {
          if (response.data) {
            if (response.data.status) {
              this.CloudLiveSet.status = response.data.status
            }
          }
        }).catch(err => {
          console.log(err)
        })
      },
      handleClickClose() {
        this.CloudLiveSet.tenantId = getTenantId();
        this.CloudLiveSet.status = '0';
        addData(this.CloudLiveSet).then(() => {
          this.$notify({
            title: '成功',
            message: '操作成功',
            type: 'success',
            duration: 2000
          });
        });
        this.$emit('close')
      }
    }
  }
</script>

<style lang="scss">
  .liveOpened {
    &-settingForm {
      p {
        color: #737373;
        margin: 0;
        margin-left: 40px;
      }

      .el-form-item__label {
        margin-right: 40px;
        font-size: 16px;
      }
    }

    &-switch {
      overflow: hidden;

      &-header {
        font-size: 16px;
        padding: 10px 20px;
        border-bottom: 1px solid #ddd;
        background-color: #fafafa;
        margin-bottom: 10px;
      }
    }
  }
</style>
